//
//  UIButton+Extension.swift
//  WiBoPM
//
//  Created by 陈俊峰 on 2017/1/6.
//  Copyright © 2017年 陈俊峰. All rights reserved.
//

import UIKit

extension UIButton{
    
    convenience init(normalTitle:String,normalTitleColor:UIColor,backgroundImage:UIImage){
        self.init()
        self.setTitle(normalTitle, for: .normal)
        self.setTitleColor(normalTitleColor, for: .normal)
        let image : UIImage = backgroundImage.resizableImage(withCapInsets: UIEdgeInsetsMake(0.5, 0.5, 0.5, 0.5))
        self.setBackgroundImage(image, for: .normal)
    }
}

extension UIImage{
    class func SnapShotCurrentScreen() -> UIImage{
        let KWindow = UIApplication.shared.keyWindow
        //开启图形上下文
        UIGraphicsBeginImageContextWithOptions((KWindow?.bounds.size)!, false, 1)
        //将当前屏幕渲染搜主窗口中
        KWindow?.drawHierarchy(in: (KWindow?.frame)!, afterScreenUpdates: true)
        //由当前图形上下文截取图片
        let snipImage =  UIGraphicsGetImageFromCurrentImageContext()
        //关闭图形上下文
        UIGraphicsEndImageContext()
        return snipImage!
    }
}
